/**
 * Created by Administrator on 2017/9/20.
 */
angular.module('module.saleStatistics')
    .controller('SaleController', SaleController);
SaleController.$inject = ['SaleService', '$localStorage', '$state'];
function SaleController(SaleService, $localStorage, $state) {

    var vm = this;
    if (!$localStorage[environmental + "shopid"]) {
        $localStorage.$reset();
        $state.go('login');
    }
    var shopid = $localStorage[environmental + "shopid"];
    var myDate = new Date();
    var time_start = new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate() - 1, 0, 0, 0).getTime();//1��ǰ��ʱ���
    var time_end = new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate() - 1, 23, 59, 59).getTime();
    //huoqu
    getBeforeDate(0);
    //console.log(getBeforeDate(0));
    SaleService.getUpInfo(shopid, time_start, time_end, function (data) {
        var tatalnum = 0;
        for (var i = 0; i < data.length; i++) {
            tatalnum = tatalnum + data[i].shopnumSum;
        }
        vm.totalnum = tatalnum;
    }, function () {
        vm.totalnum = 0;
    });

    SaleService.callInfo(shopid, time_start, time_end).$promise.then(function (success) {
        //console.log(success);
        var tatalnumcall = 0;
        for (var i = 0; i < success.length; i++) {
            tatalnumcall = tatalnumcall + success[i].frequency;
        }
        vm.tatalnumcall = tatalnumcall;
    }, function (error) {
        vm.tatalnumcall = 0;
    });

}